<%--
 *  File:    OrgOptionSetup.jsp
 *  @Author: Hilldao 
 *  Date:    2002/1/8
 *
 *  Copyright (C) 2000 - 2001 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>
<%@ page import="com.oval.util.OvalLabel" %>
<%@ page import="com.oval.util.OvalCustomColumn" %>
<%@ page import="com.oval.util.OvalCustomMessage" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<%
  //init param
  Category cat = Category.getInstance("jsp.OrgOptionSetup"); 
  String strTableName = "ovorgoption";
  String strModuleName = "SPM";
  String privilegeCode = "Z0605";
%>



<%
  //get location
  String strisFollow ="";
  String strIsChecked = "";
  String strOption = "";
  Vector optionValue = new Vector();
  
  //get userinfo
  HashMap CurUserInfo = (HashMap)session.getAttribute("userinfo");
  
  if(request.getParameter("optiontype")!=null&&(request.getParameter("optiontype").trim()).equals(""))
  {
    session.setAttribute("optiontypesession",request.getParameter("optiontype"));
  }
  
%>
<% //--------------------------------------  include files list --%>
<%@ include file="/inc/FrmDefault.inc" %>
<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>

<html>
<head>
<title></title>
<PageFlow:CheckPageFlow pageName="optionsetupsummary"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="../../js/FuncLib.js"></script>
<script language="JavaScript" src="../../css/<%= strLanguageCode %>/script.js"></script>
<%@ include file="/inc/SummaryDivision.inc" %>
<%
       

  Vector alloptions = (Vector)pageContext.getAttribute("alloptions");
  
  if(alloptions == null)
  {
    alloptions = new Vector();
  }
  Vector optiontypelist = (Vector)pageContext.getAttribute("optiontypelist");
  
  if(optiontypelist == null)
  {
    optiontypelist = new Vector();
  }
  Vector allvalue = (Vector)pageContext.getAttribute("allvalue");
  
  if(allvalue == null)
  {
    allvalue = new Vector();
  }
  cat.debug("The alloptions is :" + alloptions);
  cat.debug("The optiontypelist is :" + optiontypelist);
%>
<script>

function page_done()
{ 
    <%
     for(int p=0; p<alloptions.size() ; p++)
	 {
	   HashMap hash = (HashMap)alloptions.elementAt(p);
	   if(((Integer)hash.get("optionvaluetype")).intValue()!= 2)
		 {
		   if(((Integer)hash.get("optionvaluetype")).intValue() == 1){%>
		       var j = <%=JspHelper.filterNull( p)%>;
			   var checkvalue = eval("document.cform.optionvalue"+j).value;
			   var oldvalue = document.cform['oldoptionvalue'+j].value;
			   if(Trim(checkvalue)==Trim(oldvalue)){
		          document.cform['mdflag'+j].value=0;
	           }else {
	              document.cform['mdflag'+j].value=1;
	           }
			 <%   
		   }else{%>
		       var g = <%=JspHelper.filterNull( p)%>;
			   var obj=document.getElementById('optionvalue'+g);
	           var index =obj.selectedIndex;
	           var checkvalue = obj.options[index].value;
			   var oldvalue = document.cform['oldoptionvalue'+g].value;
			   if(Trim(checkvalue)==Trim(oldvalue)){
		          document.cform['mdflag'+g].value=0;
	           }else {
	           document.cform['mdflag'+g].value=1;
	           }
		  <% }
		 }
		else
		 {
    %>
    var k = <%=JspHelper.filterNull( p)%>;
	var boxoptionvalue = eval("document.cform.boxoptionvalue"+k);
	if (boxoptionvalue.checked == false)
      {
        addElementToForm(document.cform, "optionvalue"+k, "N",true);
       
	  }
    else
      {
      
		    addElementToForm(document.cform, "optionvalue"+k, "Y",true);
		
      }
    var checkvalue = eval("document.cform.optionvalue"+k).value;
	var oldvalue = document.cform['oldoptionvalue'+k].value;
	if(Trim(checkvalue)==Trim(oldvalue)){
		document.cform['mdflag'+k].value=0;
		//document.getElementById('tr'+k).disabled = true;
	}else {
	    document.cform['mdflag'+k].value=1;
	}
	<%}}%>
   //alert(document.getElementById('tr').childNodes.length);
    //alert(eval('document.tr'+k));
   //checkModify();
  if(checkNull(cform))
    emptyToNull(cform);
  else
    return;
	  document.cform.actionname.value = "done";
	  document.cform.target = "_self";
	  isRunning = true;
	  document.cform.submit();
}
function page_summary(actionvalue,orderbyname)
{
  var editform = summaryPrepare(cform,actionvalue,orderbyname);
  editform.action = "OrgOptionSetup.jsp?<%= OvalTools.randomURL() %>";
  editform.target = "_self";
  isRunning = true;
  editform.submit();  
}

function poporg()
{
  window.open("../../masterdata/ogm/OrgSelect.jsp?<%= OvalTools.randomURL() %>&selectoption=owner&languagecode=<%= strLanguageCode %>", "newwindow", "height=250, width=600,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
}

function page_setOrg(id, name, code){
  cform.orgname.value = name;
  cform.orgid.value = id;
 
}

function isModify(checkname,num){
	var checkvalue = document.cform[checkname+num].value;
	var oldvalue = document.cform['old'+checkname+num].value;
	if(Trim(checkvalue)==Trim(oldvalue)){
		return false;
	}else{
		return true;
	}
}



function checkModify(){
	var numrows = document.cform.numrows.value;
	for (i=0;i<numrows;i++){
		if(isModify('optionvalue',i)){
			document.cform['mdflag'+i].value=1;
			continue;
		}
			
	}
}
</script>

</head>
<body>
<table width="100%" cellspacing="0">
 <form name="cform" method="post" action="../../Dispatcher"  target="_parent">
   <input type="hidden" name="pagename" value="optionsetupsummary">
	 <input type="hidden" name="actionname">
	 <input type="hidden" name="languagecode" value="<%= strLanguageCode %>">
	 <input type="hidden" name="numrows" value="<%=JspHelper.filterNull( alloptions.size() )%>"> 
	<oval:hidden name="orgid" property="orgid"/>
		
<table width="100%" cellspacing="0">
   <% //--------------------------------------  page location --%>
	<%@ include file="/inc/PageLocation.inc" %>
</table>

<table width="100%" cellspacing="0" border="0" cellpadding="0">
  <tr> 
    <td> 
      <table width="100%" border="0" cellspacing="0">
        <tr>       
        	<% HashMap userinfo = (HashMap)session.getAttribute("userinfo"); 
        	Integer orgid1 = (Integer)userinfo.get("orgid");
        	if(orgid1.intValue()==1){%>  
           <td width="220"><%= label.getLabelName("L_Org")+label.getLabelName("L_Colon")%> 
            <custom:text property="orgname" size="20" readonly="true"/>
            <custom:hidden property="orgid" />
            <a onclick="poporg();"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a> 
          </td>    
          <%}%>
          <td width="250" height="26"><%= label.getLabelName("L_ParameterType") + label.getLabelName("L_Colon") %>  
            <custom:select optionsName="optiontypelist" optionValueKey="optiontype" optionInnerTextKey="optiontype" defaultValue="--------"  property="optiontype"/>
          <a href="javascript:page_summary('first')"><img src="../../images/<%= strLanguageCode %>/go_fy.gif" border="0" style="border: 1 solid #000000"></a>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr> 
    <td> 
      <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
       
          <tr class="deepblue-left" id='tr'> 
          <td class="title_center" width="160"><a href="javascript:page_summary('orderby','optionname')"><%= label.getLabelName("L_ParameterName") %></a></td>
          <td class="title_center"><a href="javascript:page_summary('orderby','descriptions')"><%= label.getLabelName("L_ParameterDesc") %></a></td>          
          <td class="title_center" width="140"><a href="javascript:page_summary('orderby','optionvalue')"><%= label.getLabelName("L_ParameterValue") %></a></td>
          <td class="title_center" width="60"><a href="javascript:page_summary('orderby','defaultvalue')"><%= label.getLabelName("L_DefaultValue") %></a></td>
          <td class="title_center" width="80"><a href="javascript:page_summary('orderby','isrequired')"><%= label.getLabelName("L_IsNecessary") %></a></td>
          <td class="title_center" width="80"><a href="javascript:page_summary('orderby','employeename')"><%= label.getLabelName("L_Operater") %></a></td>
          <td class="title_center" width="80"><a href="javascript:page_summary('orderby','datelastupdated')"><%= label.getLabelName("L_OperationTime") %></a></td>
         
         </tr>
        
        
        <%
             int j = 0;
             int k = 0;
             String strClassType = new String(); 
             Integer nDefaultId = new Integer(-1);
             Double dOrgInvQty=(Double)pageContext.getAttribute("orginvqty");
          %>
          <logic:iterate id="OrgOption" collection="<%= alloptions %>" indexId="idx">                      
         <%
            HashMap OrgOptionMap = (HashMap)pageContext.getAttribute("OrgOption"); 
            String isReadOnly = "";
            if(j%2 == 1){
              strClassType = "td-listrom";             
            }else{                    
              strClassType = "";
            }
             
            if(OrgOptionMap.get("rw")!=null&&(((String)OrgOptionMap.get("rw")).trim()).equalsIgnoreCase("r"))
            {
                isReadOnly = "readonly";
            } 
            
            String strOptionType =(String)OrgOptionMap.get("optiontype");
            strOptionType=(strOptionType==null)?"":strOptionType;
            String strOptionName=(String)OrgOptionMap.get("optionname");
            strOptionName=(strOptionName==null)?"":strOptionName;
            String strOptionValue=(String)OrgOptionMap.get("optionvalue");
            strOptionValue=(strOptionValue==null)?"":strOptionValue;
            if(strOptionType.equalsIgnoreCase("IWM") && strOptionName.equalsIgnoreCase("COST_METHOD") && dOrgInvQty!=null)
                isReadOnly = "readonly";
            cat.debug("readonly is :"+ (strOptionType.equalsIgnoreCase("IWM") && strOptionName.equalsIgnoreCase("COST_METHOD") && dOrgInvQty!=null));   
            j++;     
            k=j-1;
          %>
          
           <tr onmouseover="this.className='tr-over'" onmouseout="this.className='<%=JspHelper.filterNull(strClassType)%>'"   class="<%=JspHelper.filterNull(strClassType)%>" id="tr<%=idx %>">
            
             <custom:hidden name="OrgOption" property="optionvalue" changedName="oldoptionvalue" colIndex="<%=idx %>"/>
            <td><custom:write name="OrgOption" property="optionname"/>&nbsp;<input type="hidden" name="orgoptionid<%=JspHelper.filterNull(new Integer(k))%>" value="<%=JspHelper.filterNull(OrgOptionMap.get("orgoptionid"))%>" ><input type="hidden" name="optionname<%=JspHelper.filterNull(k)%>" value="<%=JspHelper.filterNull( OrgOptionMap.get("optionname") )%>" ></td>
            <td><custom:write name="OrgOption" property="descriptions"/>&nbsp;<input type="hidden" name="orgoptionid<%=JspHelper.filterNull(new Integer(k))%>" value="<%=JspHelper.filterNull(OrgOptionMap.get("orgoptionid"))%>" ></td>
            <% if(((Integer)OrgOptionMap.get("optionvaluetype")).intValue()== 1) {%>
			<td>&nbsp;<% String strss = (String)OrgOptionMap.get("isrequired");
                 if (strss != null)
                 {
                   if (strss.equals("Y"))
                   { %>
              <input type="textfield" <%=JspHelper.filterNull(isReadOnly)%> name="optionvalue<%=JspHelper.filterNull(k)%>" value="<%=JspHelper.filterNull( OrgOptionMap.get("optionvalue") )%>" isnull="N" label="<%= message.getMessageDesc("VALUE_NOT_NULL",  (String)OrgOptionMap.get("optionname")) %>">                 
                 <%}else{%>
              <input type="textfield" <%=JspHelper.filterNull(isReadOnly)%> name="optionvalue<%=JspHelper.filterNull(k)%>" value="<%=JspHelper.filterNull( OrgOptionMap.get("optionvalue") )%>" >
                 <%}
                 }%>  </td>
			<%} else if(((Integer)OrgOptionMap.get("optionvaluetype")).intValue()== 2) {
				 if(((String)OrgOptionMap.get("optionvalue")).equalsIgnoreCase("Y")) {
					 strIsChecked = "checked";
					 strOption = "Y";
				 }
				 else
				 {
					 strIsChecked = "";
					 strOption = "N";
				  }
				  %>
            <td>&nbsp;<input type="checkbox" name="boxoptionvalue<%=JspHelper.filterNull(k)%>"  class="checkbox" <%=JspHelper.filterNull(strIsChecked)%> <%=JspHelper.filterNull(isReadOnly)%>></td>
			<custom:hidden name="OrgOption" property="optionvalue" colIndex="<%=idx %>"/>
			<%}else if(((Integer)OrgOptionMap.get("optionvaluetype")).intValue()== 3) {
					 String optionName =  (String)OrgOptionMap.get("optionname") ;
					 for(int p=0 ;  p < allvalue.size() ;p++ )
					  {
					   HashMap onevalue=(HashMap)(allvalue.elementAt(p));
					   if(onevalue==null)onevalue=new HashMap();
					   String oneoptionname=(String)onevalue.get("optionname");
					   if(oneoptionname==null)oneoptionname="";
						 if(oneoptionname.equalsIgnoreCase(optionName))
						  {
							optionValue.addElement(onevalue);
						  }
					  }
					  pageContext.setAttribute("optionValue",optionValue);
					  pageContext.setAttribute("optionvalue",strOptionValue);
					  
					  %>
			<td>&nbsp;<custom:select optionsName="optionValue" optionValueKey="optionvalue" optionInnerTextKey="optionvalue::descrition" separatorChar=":" property="optionvalue" module="SPM" colIndex="<%= new Integer(k)%>"/></td>
			 <% optionValue.clear();}%> 
            <td>&nbsp;<%=JspHelper.filterNull( OrgOptionMap.get("defaultvalue") )%><input type="hidden" name="defaultvalue<%=JspHelper.filterNull(k)%>" value="<%=JspHelper.filterNull( OrgOptionMap.get("defaultvalue") )%>" ></td>
            <td>&nbsp;<%=JspHelper.filterNull( OrgOptionMap.get("isrequired") )%><input type="hidden" name="isrequired<%=JspHelper.filterNull(k)%>" value="<%=JspHelper.filterNull( OrgOptionMap.get("isrequired") )%>" >
            <input type="hidden" name="rw<%=JspHelper.filterNull(k)%>" value="<%=JspHelper.filterNull( OrgOptionMap.get("rw") )%>" >
            <input type="hidden" name="optiontype<%=JspHelper.filterNull(k)%>" value="<%=JspHelper.filterNull( OrgOptionMap.get("optiontype") )%>" >
            <input type="hidden" name="orgid<%=JspHelper.filterNull(k)%>" value="<%=JspHelper.filterNull( OrgOptionMap.get("orgid") )%>" >
            <input type="hidden" name="userid<%=JspHelper.filterNull(k)%>" value="<%=JspHelper.filterNull( (CurUserInfo.get("userid")))%>" ></td>
            
            <custom:hidden property="mdflag" colIndex="<%=idx %>" value="0"/>
            <td><custom:write name="OrgOption" property="employeename"/>&nbsp;</td>
            <td><custom:write name="OrgOption" property="datelastupdated"/>&nbsp;</td>
          </tr>
          </logic:iterate>
    <% //--------------------------------------  flipping page --%>
    <%@ include file="/inc/SummaryAction.inc" %>
      </table>
      <table width="100%" cellspacing="0" cellpadding="0">
        <tr> 
          <td class="summary_top"></td>
        </tr>
        <tr> 
          <td class="td_center"><a onclick="page_done()"><custom:button type="1" label="L_Finish" imgsrc="finish.gif" border="0" style="width:60"/></a></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</form>
</table>
</body>
</html>


